package cn.kgc.goodsdemo.service;

import cn.kgc.goodsdemo.dao.GoodsdetailMapper;
import cn.kgc.goodsdemo.pojo.Goodsdetail;
import cn.kgc.goodsdemo.pojo.GoodsdetailExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsdetailServiceImpl implements GoodsdetailService {
    @Resource
    GoodsdetailMapper goodsdetailMapper;
    @Override
    public  PageInfo<Goodsdetail> seleDetail(Integer pageNum, Integer sortid) {
        PageHelper.startPage(pageNum,2);
        List<Goodsdetail> goodsdetails;
        if(sortid==0){
         goodsdetails = goodsdetailMapper.selectByExample(null);
    }else{
        GoodsdetailExample example=new GoodsdetailExample();
        GoodsdetailExample.Criteria criteria = example.createCriteria();
         criteria.andSortidEqualTo(sortid);
         goodsdetails = goodsdetailMapper.selectByExample(example);
    }
        PageInfo<Goodsdetail> pageInfo=new PageInfo<>(goodsdetails);
        return pageInfo;
    }

    @Override
    public Goodsdetail seleById(Integer id) {
        return goodsdetailMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer up(Goodsdetail goodsdetail) {
        return goodsdetailMapper.updateByPrimaryKeySelective(goodsdetail);
    }
}
